package com.eber.demo.design.strategy;

// 策略类接口
interface Strategy {
    void execute();
}

// 具体策略A
class ConcreteStrategyA implements Strategy {
    public void execute() {
        System.out.println("策略A执行");
    }
}

// 具体策略B
class ConcreteStrategyB implements Strategy {
    public void execute() {
        System.out.println("策略B执行");
    }
}

// 环境类
class Context {
    private final Strategy strategy;

    public Context(Strategy strategy) {
        this.strategy = strategy;
    }

    public void execute() {
        this.strategy.execute();
    }
}

public class StrategyApplication {
    public static void main(String[] args) {
        // 使用策略A
        Context contextA = new Context(new ConcreteStrategyA());
        contextA.execute();

        // 使用策略B
        Context contextB = new Context(new ConcreteStrategyB());
        contextB.execute();
    }
}
